package org.subatu.orm;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.subatu.orm.entity.UserPo;
import org.subatu.orm.page.PageHelper;
import org.subatu.orm.page.PageInfo;
import org.subatu.orm.query.SqlWrapper;
import org.subatu.orm.service.UserService;

import java.util.List;

@SpringBootTest
public class UserServiceTester {

    @Autowired
    private UserService userService;
    // @Autowired
    // private SqlWrapper<UserPo> sqlWrapper;


    @Test
    public void testService() {
        List<UserPo> list = userService.lambda().like(UserPo::getName, "超级").list();
        System.out.println("list = " + list);
    }


    @Test
    public void testQuiery() throws Exception {


        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                SqlWrapper sqlWrapper = new SqlWrapper(userService);
                System.err.println("sqlWrapper = " + sqlWrapper);
                PageHelper.startPage();
                List<UserPo> list = sqlWrapper
                        .select("*")
                        .from(UserPo.class, "t")
                        .where().like(UserPo::getName, "")
                        .orderBy(UserPo::getCreateTime)
                        .list(UserPo.class);

                PageInfo localPage = PageHelper.getLocalPage();
                System.out.println("localPage = " + localPage);
                System.out.println("list = " + list);

                // sqlWrapper
                //         .select("*")
                //         .from(UserPo.class, "t")
                //         .orderBy(UserPo::getCreateTime)
                //         .list(UserPo.class);
            }).start();
        }
        Thread.sleep(2000);

    }

}
